package LintCode;

import java.util.Arrays;

/**
 * @Classname MovingTarget
 * @Description TODO
 * @Date 2021/3/3 14:35
 * @Created by ASUS
 */
public class MovingTarget {

    /**
     * @param nums:   a list of integer
     * @param target: an integer
     * @return nothing
     */
    public void MoveTarget(int[] nums, int target) {
        // write your code here
        for (int i = 0 ,j = 0; j < nums.length; j++) {
            if(nums[j] == target) {
                // System.arraycopy(nums, i, nums, i + 1, j - i);
                for (int k = j; k > i; k--) {
                    nums[k] = nums[k - 1];
                }
                nums[i++] = target;
            }
        }
        System.out.println(Arrays.toString(nums));
    }

    public static void main(String[] args) {
        new MovingTarget().MoveTarget(new int[]{3, 4, 4, 4, 4, 5, 3, 2}, 4);
    }
}
